package com.airforce.controller.base;


import com.airforce.utils.ResultCode;
import org.apache.log4j.Logger;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

;

public class BaseController {
    protected final Logger logger = Logger.getLogger(this.getClass());


    /** new PageData对象
     * @return
     */


    /**得到request对象
     * @return
     */
    public HttpServletRequest getRequest() {
        return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
    }

    public HttpServletResponse getResponse() {
        return  ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse();
    }



    public HttpSession getSession(){
        return getRequest().getSession();
    }




//    @ResponseBody
//    @ExceptionHandler({Exception.class})
//    public PageData exception(Exception e) {
//        e.printStackTrace();
//        return new PageData().fail(ResultCode.KEY_USER);
//    }
//        @Autowired
//            Jwt jwt;
//
//            public Claims getuserinfo(){
//       String getjwt= this.getRequest().getHeader("jwt");
//                System.out.println("获取jwt"+getjwt);
//      Claims body= (Claims) jwt.parse(getjwt);
//        return body;
//}






}